package com.zygh.policeasset.utils;

import cn.hutool.core.date.DateUtil;
import com.alibaba.excel.exception.ExcelAnalysisException;
import com.zygh.policeasset.component.AssetsCode;
import com.zygh.policeasset.component.DataLabelsComponent;
import com.zygh.policeasset.component.SpringJobBeanFactory;
import com.zygh.policeasset.mapper.*;
import com.zygh.policeasset.pojo.AssetCodeAuxiliary;
import com.zygh.policeasset.pojo.AssetsImages;
import com.zygh.policeasset.pojo.RoadCross;
import com.zygh.policeasset.pojo.imports.BasicsImport;
import com.zygh.policeasset.pojo.imports.DailyImport;
import com.zygh.policeasset.pojo.imports.HardwitImport;
import com.zygh.policeasset.pojo.imports.PurchaseImport;
import com.zygh.policeasset.pojo.imports.SoftwitImport;
import com.zygh.policeasset.service.AssetsImagesService;
import java.io.File;
import java.io.FileInputStream;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.io.IOUtils;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;

@Component
/* loaded from: police-asset-2.0-0.0.1-SNAPSHOT.jar:BOOT-INF/classes/com/zygh/policeasset/utils/ImportListenerUtil.class */
public class ImportListenerUtil {
    DataLabelsComponent dataLabelsComponent = (DataLabelsComponent) SpringJobBeanFactory.getBean(DataLabelsComponent.class);

    public void checkDataHardwitQrcode(List<HardwitImport> data, String projectNo, Integer sectionId, Integer rowIndex) {
        QrCodeGeneratedMapper qrCodeGeneratedMapper = (QrCodeGeneratedMapper) SpringJobBeanFactory.getBean(QrCodeGeneratedMapper.class);
        Integer integer = qrCodeGeneratedMapper.selectCountByBuildNum(projectNo, sectionId);
        List<String> list = new ArrayList<>();
        int length = data.size();
        for (int i = 0; i < length; i++) {
            if (!StringUtils.isEmpty(data.get(i).getQrCode())) {
                if (qrCodeGeneratedMapper.selectCountByBuildNumAndSectionId(projectNo, sectionId, data.get(i).getQrCode()).intValue() == 0) {
                    throw new ExcelAnalysisException("-第" + rowIndex + "行：上传文件中二维码编号和已领取二维码不一致，请检查二维码编号是否正确");
                }
                list.add(data.get(i).getQrCode());
            }
        }
        if (integer.intValue() != list.size()) {
            throw new ExcelAnalysisException("-上传文件中二维码编号数据和已领取二维码数量不一致");
        }
    }
    public HardwitImport checkDataHardwit(HardwitImport data, String projectNo, String inputNum, String sectionName, Integer sectionId, Integer companyId, String type, Integer selfBuilt, Integer rowIndex) {
        data.setCreateTime(DateUtil.now());
        data.setSelfBuilt(selfBuilt);
        data.setBuildNum(projectNo);
        data.setUserId(inputNum);
        data.setSectionName(sectionName);
        data.setSectionId(sectionId);
        data.setCompanyId(companyId);
        data.setAssetsType("znh");
        data.setDeviceType("zn");
        data.setCombined(Double.valueOf(data.getUnitPrice()));
        DataLabelsComponent dataLabelsComponent = this.dataLabelsComponent;
        data.setDataLabelsId(DataLabelsComponent.toEnableId);
        data.setAssetsTypeName("智能硬件");
        data.setAssetsStatusName("新增");
        data.setAssetDisposalName("正常");
        String witbigNum = null;
        if (CheckObjAllFieldsIsNull.checkObjAllFieldsIsNullHardwit(data)) {
            throw new ExcelAnalysisException("-请填充完整数据！第" + rowIndex + "行");
        } else if (!isValidDate(data.getStartDatetime(), "yyyy-MM-dd")) {
            throw new ExcelAnalysisException("-时间格式不对,请参照2000-01-01格式填写！第" + rowIndex + "行");
        } else if (!isValidDate(data.getCompletionTime(), "yyyy-MM-dd")) {
            throw new ExcelAnalysisException("-时间格式不对,请参照2000-01-01格式填写！第" + rowIndex + "行");
        } else {
            if (!StringUtils.isEmpty(data.getBigName())) {
                witbigNum = ((WitbigMapper) SpringJobBeanFactory.getBean(WitbigMapper.class)).findOneByName(type, data.getBigName());
                if (StringUtils.isEmpty(witbigNum)) {
                    throw new ExcelAnalysisException("-硬件资产统计sheet表中第" + rowIndex + "行：资产大类与平台规范不一致");
                }
                data.setBigNum(witbigNum);
                data.setBigName(data.getBigName());
            }
            if (!StringUtils.isEmpty(data.getSmallName())) {
                WitsmallMapper witsmallMapper = (WitsmallMapper) SpringJobBeanFactory.getBean(WitsmallMapper.class);
                String witsmallNum = witsmallMapper.findOneByName(type, witbigNum, data.getSmallName());
                if (StringUtils.isEmpty(witsmallNum)) {
                    throw new ExcelAnalysisException("-硬件资产统计sheet表中第" + rowIndex + "行：资产小类与平台规范不一致");
                }
                data.setSmallNum(witsmallNum);
                data.setSmallName(data.getSmallName());
                if (witsmallMapper.findDepreciation("zn", witbigNum, witsmallNum) != data.getDepreciationYear()) {
                    throw new ExcelAnalysisException("-硬件资产统计sheet表中第" + rowIndex + "行：资产折旧年限与平台大类小类折旧年限不一致");
                }
            }
            UnitMapper unitMapper = (UnitMapper) SpringJobBeanFactory.getBean(UnitMapper.class);
            if (!StringUtils.isEmpty(data.getConstrucUnitName())) {
                String ConstrucUnit = unitMapper.findOneByName("zd", data.getConstrucUnitName());
                if (StringUtils.isEmpty(ConstrucUnit)) {
                    throw new ExcelAnalysisException("-硬件资产统计sheet表中第" + rowIndex + "行：建设单位与平台规范不一致");
                }
                data.setConstrucUnit(ConstrucUnit);
                data.setConstrucUnitName(data.getConstrucUnitName());
            }
            if (!StringUtils.isEmpty(data.getBuildUnitName())) {
                String BuildUnit = unitMapper.findOneByName(type, data.getBuildUnitName());
                if (StringUtils.isEmpty(BuildUnit)) {
                    throw new ExcelAnalysisException("-硬件资产统计sheet表中第" + rowIndex + "行：承建单位与平台规范不一致");
                }
                data.setBuildUnit(BuildUnit);
                data.setBuildUnitName(data.getBuildUnitName());
            }
            if (!StringUtils.isEmpty(data.getMaintainUnitName())) {
                String MaintainUnit = unitMapper.findOneByName(type, data.getMaintainUnitName());
                if (StringUtils.isEmpty(MaintainUnit)) {
                    throw new ExcelAnalysisException("-硬件资产统计sheet表中第" + rowIndex + "行：运维单位与平台规范不一致");
                }
                data.setMaintainUnit(MaintainUnit);
                data.setMaintainUnitName(data.getMaintainUnitName());
            }
            if (!StringUtils.isEmpty(data.getWhetherEnableName())) {
                if (!data.getWhetherEnableName().equals("未启用") && !data.getWhetherEnableName().equals("已启用")) {
                    throw new ExcelAnalysisException("-硬件资产统计sheet表中第" + rowIndex + "行：请填写已启用或未启用");
                } else if (data.getWhetherEnableName().equals("未启用")) {
                    data.setWhetherEnable(0);
                } else if (data.getWhetherEnableName().equals("已启用")) {
                    data.setWhetherEnable(1);
                }
            }
            String assetsNum = ((AssetsCode) SpringJobBeanFactory.getBean(AssetsCode.class)).getZNJC("ZN", data.getBigNum(), data.getSmallNum(), data.getCompletionTime(), projectNo, sectionId);
            if (!StringUtils.isEmpty(assetsNum)) {
                data.setAssetNum(assetsNum);
            }
            return data;
        }
    }

    public void checkDataBasicsQrcode(List<BasicsImport> data, String projectNo, Integer sectionId, Integer rowIndex) {
        QrCodeGeneratedMapper qrCodeGeneratedMapper = (QrCodeGeneratedMapper) SpringJobBeanFactory.getBean(QrCodeGeneratedMapper.class);
        Integer integer = qrCodeGeneratedMapper.selectCountByBuildNum(projectNo, sectionId);
        List<String> list = new ArrayList<>();
        int length = data.size();
        for (int i = 0; i < length; i++) {
            if (!StringUtils.isEmpty(data.get(i).getQrCode())) {
                if (qrCodeGeneratedMapper.selectCountByBuildNumAndSectionId(projectNo, sectionId, data.get(i).getQrCode()).intValue() == 0) {
                    throw new ExcelAnalysisException("-第" + rowIndex + "行：上传文件中二维码编号和已领取二维码不一致，请检查二维码编号是否正确");
                }
                list.add(data.get(i).getQrCode());
            }
        }
        if (integer.intValue() != list.size()) {
            throw new ExcelAnalysisException("-上传文件中二维码编号数据和已领取二维码数量不一致");
        }
    }

    public BasicsImport checkDataBasics(BasicsImport data, String projectNo, String inputNum, String sectionName, Integer sectionId, Integer companyId, String type, Integer selfBuilt, Integer rowIndex, String time) {
        data.setCreateTime(DateUtil.now());
        data.setSelfBuilt(selfBuilt);
        data.setBuildNum(projectNo);
        data.setUserId(inputNum);
        data.setSectionName(sectionName);
        data.setSectionId(sectionId);
        data.setCompanyId(companyId);
        data.setAssetsType("jc");
        data.setDeviceType("jc");
        data.setAssetsTypeName("基础");
        data.setAssetsStatusName("新增");
        data.setAssetDisposalName("正常");
        DataLabelsComponent dataLabelsComponent = this.dataLabelsComponent;
        data.setDataLabelsId(DataLabelsComponent.toEnableId);
        if (CheckObjAllFieldsIsNull.checkObjAllFieldsIsNullBasics(data)) {
            throw new ExcelAnalysisException("-请填充完整数据！第" + rowIndex + "行");
        } else if (!isValidDate(data.getStartDatetime(), "yyyy-MM-dd")) {
            throw new ExcelAnalysisException("-时间格式不对,请参照2000-01-01格式填写！第" + rowIndex + "行");
        } else if (!isValidDate(data.getCompletionTime(), "yyyy-MM-dd")) {
            throw new ExcelAnalysisException("-时间格式不对,请参照2000-01-01格式填写！第" + rowIndex + "行");
        } else {
            String witbigNum = null;
            if (!StringUtils.isEmpty(data.getBigName())) {
                witbigNum = ((WitbigMapper) SpringJobBeanFactory.getBean(WitbigMapper.class)).findOneByName(type, data.getBigName());
                if (StringUtils.isEmpty(witbigNum)) {
                    throw new ExcelAnalysisException("-第" + rowIndex + "行：资产大类与平台规范不一致");
                }
                data.setBigNum(witbigNum);
                data.setBigName(data.getBigName());
            }
            if (!StringUtils.isEmpty(data.getSmallName())) {
                WitsmallMapper witsmallMapper = (WitsmallMapper) SpringJobBeanFactory.getBean(WitsmallMapper.class);
                String witsmallNum = witsmallMapper.findOneByName(type, witbigNum, data.getSmallName());
                if (StringUtils.isEmpty(witsmallNum)) {
                    throw new ExcelAnalysisException("-第" + rowIndex + "行：资产小类与平台规范不一致");
                }
                data.setSmallNum(witsmallNum);
                data.setSmallName(data.getSmallName());
                if (witsmallMapper.findDepreciation("jc", witbigNum, witsmallNum) != data.getDepreciationYear()) {
                    throw new ExcelAnalysisException("-基础资产统计sheet表中第" + rowIndex + "行：资产折旧年限与平台大类小类折旧年限不一致");
                }
            }
            UnitMapper unitMapper = (UnitMapper) SpringJobBeanFactory.getBean(UnitMapper.class);
            if (!StringUtils.isEmpty(data.getConstrucUnitName())) {
                String ConstrucUnit = unitMapper.findOneByName("zd", data.getConstrucUnitName());
                if (StringUtils.isEmpty(ConstrucUnit)) {
                    throw new ExcelAnalysisException("-第" + rowIndex + "行：建设单位与平台规范不一致");
                }
                data.setConstrucUnit(ConstrucUnit);
                data.setConstrucUnitName(data.getConstrucUnitName());
            }
            if (!StringUtils.isEmpty(data.getBuildUnitName())) {
                String BuildUnit = unitMapper.findOneByName(type, data.getBuildUnitName());
                if (StringUtils.isEmpty(BuildUnit)) {
                    throw new ExcelAnalysisException("-第" + rowIndex + "行：承建单位与平台规范不一致");
                }
                data.setBuildUnit(BuildUnit);
                data.setBuildUnitName(data.getBuildUnitName());
            }
            data.setAdditionalNumber(getAdditionalNumber(time, data.getSerialNum(), "jc"));
            AssetsCode assetsCode = (AssetsCode) SpringJobBeanFactory.getBean(AssetsCode.class);
            if (!"01".equals(witbigNum) || "移动信号灯".equals(data.getSmallName())) {
                AssetCodeAuxiliaryMapper assetCodeAuxiliaryMapper = (AssetCodeAuxiliaryMapper) SpringJobBeanFactory.getBean(AssetCodeAuxiliaryMapper.class);
                AssetCodeAuxiliary assetCodeAuxiliary = assetCodeAuxiliaryMapper.findAssetCodeAuxiliary(time, "jc", data.getSerialNum());
                if (StringUtils.isEmpty(assetCodeAuxiliary)) {
                    String assetsNum = assetsCode.getZNJC("JC", data.getBigNum(), data.getSmallNum(), data.getCompletionTime(), projectNo, sectionId);
                    assetCodeAuxiliaryMapper.updateAssetsNum(time, "jc", assetsNum, data.getSerialNum());
                    data.setAssetNum(assetsNum);
                } else {
                    data.setAssetNum(assetCodeAuxiliary.getAssetsNum());
                }
            } else {
                RoadCrossMapper roadCrossMapper = (RoadCrossMapper) SpringJobBeanFactory.getBean(RoadCrossMapper.class);
                RoadCross roadCross = roadCrossMapper.findByName(data.getPlace());
                if (StringUtils.isEmpty(roadCross)) {
                    throw new ExcelAnalysisException("-第" + rowIndex + "行：详细位置与平台规范不一致");
                } else if (StringUtils.isEmpty(roadCross.getAssetNum())) {
                    String assetsNum2 = assetsCode.getZNJC("JC", data.getBigNum(), data.getSmallNum(), data.getCompletionTime(), projectNo, sectionId);
                    roadCrossMapper.updateById(new RoadCross().setAssetNum(assetsNum2).setId(roadCross.getId()));
                    data.setAssetNum(assetsNum2);
                } else {
                    data.setAssetNum(roadCross.getAssetNum());
                }
            }
            return data;
        }
    }

    public String getAdditionalNumber(String time, Integer serialNum, String type) {
        AssetCodeAuxiliaryMapper assetCodeAuxiliaryMapper = (AssetCodeAuxiliaryMapper) SpringJobBeanFactory.getBean(AssetCodeAuxiliaryMapper.class);
        assetCodeAuxiliaryMapper.add(new AssetCodeAuxiliary().setTimeNum(time).setSerialNum(serialNum).setType(type));
        Integer count = assetCodeAuxiliaryMapper.findCount(time, serialNum, type);
        if (count.intValue() > 9) {
            return count.toString();
        }
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append("0");
        stringBuffer.append(count.toString());
        return stringBuffer.toString();
    }

    public void checkDataDailyQrcode(List<DailyImport> data, String projectNo, Integer rowIndex) {
        QrCodeGeneratedMapper qrCodeGeneratedMapper = (QrCodeGeneratedMapper) SpringJobBeanFactory.getBean(QrCodeGeneratedMapper.class);
        Integer integer = qrCodeGeneratedMapper.selectCountByBuildNum(projectNo, null);
        List<String> list = new ArrayList<>();
        int length = data.size();
        for (int i = 0; i < length; i++) {
            if (!StringUtils.isEmpty(data.get(i).getQrCode())) {
                if (qrCodeGeneratedMapper.selectCountByBuildNumAndSectionId(projectNo, null, data.get(i).getQrCode()).intValue() == 0) {
                    throw new ExcelAnalysisException("-上传文件中二维码编号和已领取二维码不一致，请检查所有二维码编号是否正确");
                }
                list.add(data.get(i).getQrCode());
            }
        }
        if (integer.intValue() != list.size()) {
            throw new ExcelAnalysisException("-上传文件中二维码编号数据和已领取二维码数量不一致");
        }
    }

    public DailyImport checkDataDaily(DailyImport data, String projectNo, String inputNum, Integer companyId, Integer selfBuilt, String projectType, Integer rowIndex, String time) {
        data.setCreateTime(DateUtil.now());
        data.setBuildNum(projectNo);
        data.setUserId(inputNum);
        data.setCompanyId(companyId);
        data.setAssetsType("da");
        data.setAssetsTypeName("日常");
        data.setAssetsStatusName("新增");
        data.setAssetDisposalName("正常");
        data.setDeviceType(projectType);
        data.setSelfBuilt(selfBuilt);
        DataLabelsComponent dataLabelsComponent = this.dataLabelsComponent;
        data.setDataLabelsId(DataLabelsComponent.toEnableId);
        data.setDeviceType(projectType);
        boolean flag1 = CheckObjAllFieldsIsNull.checkObjAllFieldsIsNullBasics(data);
        System.out.println(flag1);
        System.out.println(data);
        if (flag1) {
            throw new ExcelAnalysisException("-请填充完整数据！第" + rowIndex + "行");
        } else if (!isValidDate(data.getStartDatetime(), "yyyy-MM-dd")) {
            throw new ExcelAnalysisException("-时间格式不对,请参照2000-01-01格式填写！第" + rowIndex + "行");
        } else if (!isValidDate(data.getCompletionTime(), "yyyy-MM-dd")) {
            throw new ExcelAnalysisException("-时间格式不对,请参照2000-01-01格式填写！第" + rowIndex + "行");
        } else {
            String witbigNum = null;
            if (!StringUtils.isEmpty(data.getBigName())) {
                witbigNum = ((WitbigMapper) SpringJobBeanFactory.getBean(WitbigMapper.class)).findOneByName(projectType, data.getBigName());
                if (StringUtils.isEmpty(witbigNum)) {
                    throw new ExcelAnalysisException("-第" + rowIndex + "行：资产大类与平台规范不一致");
                }
                data.setBigNum(witbigNum);
                data.setBigName(data.getBigName());
            }
            String witsmallNum = null;
            WitsmallMapper witsmallMapper = (WitsmallMapper) SpringJobBeanFactory.getBean(WitsmallMapper.class);
            if (!StringUtils.isEmpty(data.getSmallName())) {
                witsmallNum = witsmallMapper.findOneByName(projectType, witbigNum, data.getSmallName());
                if (StringUtils.isEmpty(witsmallNum)) {
                    throw new ExcelAnalysisException("-第" + rowIndex + "行：资产小类查与平台规范不一致");
                }
                data.setSmallNum(witsmallNum);
                data.setSmallName(data.getSmallName());
            }
            if (witsmallMapper.findDepreciation(projectType, witbigNum, witsmallNum) != data.getDepreciationYear()) {
                throw new ExcelAnalysisException("-日常资产统计sheet表中第" + rowIndex + "行：资产折旧年限与平台大类小类折旧年限不一致");
            }
            UnitMapper unitMapper = (UnitMapper) SpringJobBeanFactory.getBean(UnitMapper.class);
            if (!StringUtils.isEmpty(data.getConstrucUnitName())) {
                String ConstrucUnit = unitMapper.findOneByName("zd", data.getConstrucUnitName());
                if (StringUtils.isEmpty(ConstrucUnit)) {
                    throw new ExcelAnalysisException("-第" + rowIndex + "行：建设单位与平台规范不一致");
                }
                data.setConstrucUnit(ConstrucUnit);
                data.setConstrucUnitName(data.getConstrucUnitName());
            }
            if (!StringUtils.isEmpty(data.getBuildUnitName())) {
                String BuildUnit = unitMapper.findOneByName(projectType, data.getBuildUnitName());
                if (StringUtils.isEmpty(BuildUnit)) {
                    throw new ExcelAnalysisException("-第" + rowIndex + "行：承建单位与平台规范不一致");
                }
                data.setBuildUnit(BuildUnit);
                data.setBuildUnitName(data.getBuildUnitName());
            }
            if ("jc".equals(projectType)) {
                projectType = "JC";
            } else if ("zn".equals(projectType)) {
                projectType = "ZN";
            }
            data.setAdditionalNumber(getAdditionalNumber(time, data.getSerialNum(), "da"));
            AssetsCode assetsCode = (AssetsCode) SpringJobBeanFactory.getBean(AssetsCode.class);
            if (!"01".equals(witbigNum) || !"JC".equals(projectType) || "移动信号灯".equals(data.getSmallName())) {
                AssetCodeAuxiliaryMapper assetCodeAuxiliaryMapper = (AssetCodeAuxiliaryMapper) SpringJobBeanFactory.getBean(AssetCodeAuxiliaryMapper.class);
                AssetCodeAuxiliary assetCodeAuxiliary = assetCodeAuxiliaryMapper.findAssetCodeAuxiliary(time, "da", data.getSerialNum());
                if (StringUtils.isEmpty(assetCodeAuxiliary)) {
                    String assetsNum = assetsCode.getZNJC(projectType, data.getBigNum(), data.getSmallNum(), data.getCompletionTime(), projectNo, null);
                    assetCodeAuxiliaryMapper.updateAssetsNum(time, "da", assetsNum, data.getSerialNum());
                    data.setAssetNum(assetsNum);
                } else {
                    data.setAssetNum(assetCodeAuxiliary.getAssetsNum());
                }
            } else {
                RoadCrossMapper roadCrossMapper = (RoadCrossMapper) SpringJobBeanFactory.getBean(RoadCrossMapper.class);
                RoadCross roadCross = roadCrossMapper.findByName(data.getPlace());
                if (StringUtils.isEmpty(roadCross)) {
                    throw new ExcelAnalysisException("-第" + rowIndex + "行：详细位置与平台规范不一致");
                } else if (StringUtils.isEmpty(roadCross.getAssetNum())) {
                    String assetsNum2 = assetsCode.getZNJC(projectType, data.getBigNum(), data.getSmallNum(), data.getCompletionTime(), projectNo, null);
                    roadCrossMapper.updateById(new RoadCross().setAssetNum(assetsNum2).setId(roadCross.getId()));
                    data.setAssetNum(assetsNum2);
                } else {
                    data.setAssetNum(roadCross.getAssetNum());
                }
            }
            return data;
        }
    }

    public void checkDataPurchaseQrcode(List<PurchaseImport> data, String projectNo, Integer rowIndex) {
        QrCodeGeneratedMapper qrCodeGeneratedMapper = (QrCodeGeneratedMapper) SpringJobBeanFactory.getBean(QrCodeGeneratedMapper.class);
        Integer integer = qrCodeGeneratedMapper.selectCountByBuildNum(projectNo, null);
        List<String> list = new ArrayList<>();
        int length = data.size();
        for (int i = 0; i < length; i++) {
            if (!StringUtils.isEmpty(data.get(i).getQrCode())) {
                if (qrCodeGeneratedMapper.selectCountByBuildNumAndSectionId(projectNo, null, data.get(i).getQrCode()).intValue() == 0) {
                    throw new ExcelAnalysisException("-第" + rowIndex + "行：上传文件中二维码编号和已领取二维码不一致，请检查二维码编号是否正确");
                }
                list.add(data.get(i).getQrCode());
            }
        }
        if (integer.intValue() != list.size()) {
            throw new ExcelAnalysisException("-上传文件中二维码编号数据和已领取二维码数量不一致");
        }
    }

    public PurchaseImport checkDataPurchase(PurchaseImport data, String projectNo, String inputNum, Integer selfBuilt, Integer rowIndex) {
        data.setCreateTime(DateUtil.now());
        data.setBuildNum(projectNo);
        data.setUserId(inputNum);
        data.setAssetsType("cg");
        DataLabelsComponent dataLabelsComponent = this.dataLabelsComponent;
        data.setDataLabelsId(DataLabelsComponent.toEnableId);
        data.setAssetsTypeName("采购");
        data.setAssetsStatusName("新增");
        data.setAssetDisposalName("正常");
        data.setUnitPrice(data.getCombined());
        data.setSelfBuilt(selfBuilt);
        System.out.println(data);
        if (CheckObjAllFieldsIsNull.checkObjAllFieldsIsNullPurchase(data)) {
            throw new ExcelAnalysisException("-请填充完整数据！第" + rowIndex + "行");
        } else if (!isValidDate(data.getGetDatetime(), "yyyy-MM-dd")) {
            throw new ExcelAnalysisException("-时间格式不对,请参照2000-01-01格式填写！第" + rowIndex + "行");
        } else if (!isValidDate(data.getStartDatetime(), "yyyy-MM-dd")) {
            throw new ExcelAnalysisException("-时间格式不对,请参照2000-01-01格式填写！第" + rowIndex + "行");
        } else if (!isValidDate(data.getGuaranteeStopDatetime(), "yyyy-MM-dd")) {
            throw new ExcelAnalysisException("-时间格式不对,请参照2000-01-01格式填写！第" + rowIndex + "行");
        } else if (StringUtils.isEmpty(data.getUseUser())) {
            throw new ExcelAnalysisException("-第" + rowIndex + "行：使用人不能为空");
        } else if (StringUtils.isEmpty(data.getManageDepartment())) {
            throw new ExcelAnalysisException("-第" + rowIndex + "行：管理部门不能为空");
        } else {
            if (!StringUtils.isEmpty(data.getUseDepartment())) {
                String ConstrucUnit = ((DepartmentMapper) SpringJobBeanFactory.getBean(DepartmentMapper.class)).findByDepartment(data.getUseDepartment());
                System.out.println("采购使用部门与>>>>>>>>>>>" + ConstrucUnit);
                if (StringUtils.isEmpty(ConstrucUnit)) {
                    throw new ExcelAnalysisException("-第" + rowIndex + "行：采购使用部门与平台规范不一致");
                }
                data.setUseDepartment(ConstrucUnit);
            }
            if (!StringUtils.isEmpty(data.getRetailer())) {
                String ConstrucUnit2 = ((UnitMapper) SpringJobBeanFactory.getBean(UnitMapper.class)).findOneByName("cg", data.getRetailer());
                if (StringUtils.isEmpty(ConstrucUnit2)) {
                    throw new ExcelAnalysisException("-第" + rowIndex + "行：销售商与平台规范不一致");
                }
                data.setRetailer(ConstrucUnit2);
            }
            String assetsNum = ((AssetsCode) SpringJobBeanFactory.getBean(AssetsCode.class)).getZD("ZD", data.getGetDatetime(), data.getUseDepartment(), projectNo);
            if (!StringUtils.isEmpty(assetsNum)) {
                data.setAssetNum(assetsNum);
            }
            System.out.println(data);
            return data;
        }
    }

    public SoftwitImport checkDataSoftwit(SoftwitImport data, String projectNo, String inputNum, String sectionName, Integer sectionId, Integer companyId, String type, Integer selfBuilt, Integer rowIndex) {
        data.setCreateTime(DateUtil.now());
        data.setBuildNum(projectNo);
        data.setUserId(inputNum);
        data.setSectionName(sectionName);
        data.setSectionId(sectionId);
        data.setCompanyId(companyId);
        data.setAssetsType("zns");
        data.setDeviceType("zn");
        data.setAssetsTypeName("智能软件");
        data.setAssetsStatusName("新增");
        data.setAssetDisposalName("正常");
        data.setSelfBuilt(selfBuilt);
        DataLabelsComponent dataLabelsComponent = this.dataLabelsComponent;
        data.setDataLabelsId(DataLabelsComponent.toEnableId);
        data.setCombined(data.getUnitPrice());
        if (!isValidDate(data.getStartDatetime(), "yyyy-MM-dd")) {
            throw new ExcelAnalysisException("-时间格式不对,请参照2000-01-01格式填写！第" + rowIndex + "行");
        } else if (!isValidDate(data.getCompletionTime(), "yyyy-MM-dd")) {
            throw new ExcelAnalysisException("-时间格式不对,请参照2000-01-01格式填写！第" + rowIndex + "行");
        } else {
            String witbigNum = null;
            if (!StringUtils.isEmpty(data.getBigName())) {
                witbigNum = ((WitbigMapper) SpringJobBeanFactory.getBean(WitbigMapper.class)).findOneByName(type, data.getBigName());
                if (StringUtils.isEmpty(witbigNum)) {
                    throw new ExcelAnalysisException("-软件资产统计sheet表中第" + rowIndex + "行：资产大类与平台规范不一致");
                }
                data.setBigNum(witbigNum);
                data.setBigName(data.getBigName());
            }
            if (!StringUtils.isEmpty(data.getSmallName())) {
                WitsmallMapper witsmallMapper = (WitsmallMapper) SpringJobBeanFactory.getBean(WitsmallMapper.class);
                String witsmallNum = witsmallMapper.findOneByName(type, witbigNum, data.getSmallName());
                if (StringUtils.isEmpty(witsmallNum)) {
                    throw new ExcelAnalysisException("-软件资产统计sheet表中第" + rowIndex + "行：资产小类与平台规范不一致");
                }
                data.setSmallNum(witsmallNum);
                data.setSmallName(data.getSmallName());
                if (witsmallMapper.findDepreciation("zn", witbigNum, witsmallNum) != data.getDepreciationYear()) {
                    throw new ExcelAnalysisException("-软件资产统计sheet表中第" + rowIndex + "行：资产折旧年限与平台大类小类折旧年限不一致");
                }
            }
            if (!StringUtils.isEmpty(data.getWhetherEnableName())) {
                if (!data.getWhetherEnableName().equals("未启用") && !data.getWhetherEnableName().equals("已启用")) {
                    throw new ExcelAnalysisException("-硬件资产统计sheet表中第" + rowIndex + "行：请填写已启用或未启用");
                } else if (data.getWhetherEnableName().equals("未启用")) {
                    data.setWhetherEnable(0);
                } else if (data.getWhetherEnableName().equals("已启用")) {
                    data.setWhetherEnable(1);
                }
            }
            UnitMapper unitMapper = (UnitMapper) SpringJobBeanFactory.getBean(UnitMapper.class);
            if (!StringUtils.isEmpty(data.getConstrucUnitName())) {
                String ConstrucUnit = unitMapper.findOneByName("zd", data.getConstrucUnitName());
                if (StringUtils.isEmpty(ConstrucUnit)) {
                    throw new ExcelAnalysisException("-软件资产统计sheet表中第" + rowIndex + "行：软件建设单位与平台规范不一致");
                }
                data.setConstrucUnit(ConstrucUnit);
                data.setConstrucUnitName(data.getConstrucUnitName());
            }
            if (!StringUtils.isEmpty(data.getBuildUnitName())) {
                String BuildUnit = unitMapper.findOneByName(type, data.getBuildUnitName());
                if (StringUtils.isEmpty(BuildUnit)) {
                    throw new ExcelAnalysisException("-软件资产统计sheet表中第" + rowIndex + "行：软件承建单位与平台规范不一致");
                }
                data.setBuildUnit(BuildUnit);
                data.setBuildUnitName(data.getBuildUnitName());
            }
            if (!StringUtils.isEmpty(data.getMaintainUnitName())) {
                String MaintainUnit = unitMapper.findOneByName(type, data.getMaintainUnitName());
                if (StringUtils.isEmpty(MaintainUnit)) {
                    throw new ExcelAnalysisException("-软件资产统计sheet表中第" + rowIndex + "行：硬件运维单位与平台规范不一致");
                }
                data.setMaintainUnit(MaintainUnit);
                data.setMaintainUnitName(data.getMaintainUnitName());
            }
            String assetsNum = ((AssetsCode) SpringJobBeanFactory.getBean(AssetsCode.class)).getZNJC("ZN", data.getBigNum(), data.getSmallNum(), data.getCompletionTime(), data.getBuildNum(), data.getSectionId());
            if (!StringUtils.isEmpty(assetsNum)) {
                data.setAssetNum(assetsNum);
            }
            return data;
        }
    }

    public Integer addimage(Integer id, String imageUrl, String pactName, String projectNo, String type) {
        AssetsImages assetsImages = new AssetsImages();
        assetsImages.setType(type);
        assetsImages.setIcon(createFileItem(imageUrl));
        assetsImages.setAssetsId(id);
        assetsImages.setBuildNum(projectNo);
        return ((AssetsImagesService) SpringJobBeanFactory.getBean(AssetsImagesService.class)).add(assetsImages);
    }

    public MultipartFile createFileItem(String filePath) {
        FileInputStream inputStream = null;
        try {
            MultipartFile multipartFile = null;
            try {
                File pdfFile = new File(filePath);
                inputStream = new FileInputStream(pdfFile);
                multipartFile = new MockMultipartFile("file", pdfFile.getName(), "text/plain", IOUtils.toByteArray(inputStream));
                if (inputStream != null) {
                    try {
                        inputStream.close();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            } catch (Exception e2) {
                e2.printStackTrace();
                if (inputStream != null) {
                    try {
                        inputStream.close();
                    } catch (Exception e3) {
                        e3.printStackTrace();
                    }
                }
            }
            return multipartFile;
        } catch (Throwable th) {
            if (inputStream != null) {
                try {
                    inputStream.close();
                } catch (Exception e4) {
                    e4.printStackTrace();
                    throw th;
                }
            }
            throw th;
        }
    }

    public static boolean isValidDate(String str, String format) {
        if (format == null) {
            format = "yyyy-MM-dd HH:mm:ss";
        }
        boolean convertSuccess = true;
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        try {
            sdf.setLenient(false);
            sdf.parse(str);
            if (str.length() != format.length()) {
                convertSuccess = false;
            }
        } catch (ParseException e) {
            convertSuccess = false;
        }
        return convertSuccess;
    }
}